from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time


branch='v2.01.33'
serverversion=''
version='.01'

branchversion =  branch+version

#获取浏览器对象
browser =  webdriver.Chrome()
browser.get("http://jenkins.baidu.com/login?from=%2Fview%2Fzhpw%2F")
# username  = browser.find_element(By.XPATH,'//*[@id="app"]/div/div/div[2]/div[2]/div/form/div[1]/div/div/input')
username  = browser.find_element(By.XPATH,'//input[contains(@placeholder,\'用户名\')]')
username.send_keys('jun.wang')

password  = browser.find_element(By.XPATH,'//input[contains(@placeholder,\'密码\')]')
password.send_keys('wj123456*')

login = browser.find_element(By.XPATH,'/html/body/div/div/form/div[3]/input')
login.click()

testtmhpw = browser.find_element(By.XPATH,'//a[contains(@href,\'/view/test-tmhpw/\')]')
testtmhpw.click()

publish = browser.find_element(By.XPATH,'//a[contains(@href,\'job/test_tmhpw-publish/\')]')
publish.click()

pwPublish = browser.find_element(By.XPATH,'//*[@id="job_test_tmhpw-sendinfo-pwServer-publish"]/td[3]/a')
pwPublish.click()

buildwithParam = browser.find_element(By.XPATH,'//*[@id="tasks"]/div[5]/a[2]')
buildwithParam.click()

serverReleaseVersion = browser.find_element(By.XPATH,'//*[@id="main-panel"]/form/table/tbody[1]/tr[1]/td[3]/div/input[2]')
serverReleaseVersion.send_keys(branch+serverversion)

smardCardVersion = browser.find_element(By.XPATH,'//*[@id="main-panel"]/form/table/tbody[2]/tr[1]/td[3]/div/input[2]')
smardCardVersion.send_keys('v.1.8.4')

pwReleaseVersion = browser.find_element(By.XPATH,'//*[@id="main-panel"]/form/table/tbody[3]/tr[1]/td[3]/div/input[2]')
pwReleaseVersion.send_keys(branchversion)

time.sleep(2)
select = browser.find_element(By.ID,"gitParameterSelect")
option =select.find_element(By.XPATH,"//option[@value=\'origin/release/release-"+branch+"\']")
option.click()

build = browser.find_element(By.XPATH,'//*[@id="yui-gen1-button"]')
build.click()

time.sleep(10)
browser.close()
